/**
 * Created by QIAODI on 8/24/2016.
 */
const mongoose = require("mongoose");
const request = require("request");
const async = require('async');
var Order = mongoose.model("order");

exports.getOrders = function (req, res) {
    var oids = JSON.parse(req.body.oids);
    var orderDetails = {};

    async.each(oids, function (oid, callback) {
        Order.findOne({_id: oid}).populate("merchant").populate("client")
            .exec(function (err, orders) {
                if (!err) {
                    orderDetails[oid] = orders;
                    callback();
                }
                else {
                    res.json({error: "orderDetails"});
                }
            });
    }, function (err) {
        console.log(orderDetails);
        res.json(orderDetails);
    });
}
